﻿// /////////////////////////////////// 
//  
//  
//      WiseLink CCF2.0 
//     (c)Copyright 2001-2010 WiseLink Xiaojun (David) Chen 
//        Authored and Owned Xiaojun (David) Chen 
//        All Right Reserved
//  
// /////////////////////////////////// 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;

namespace Infrastructure.Log
{
    
        public static class CallLogger
        {
            static ILog log;

            
            public static void LogPairValue(Type callerType,string callName, IDictionary<string, string> parameters)
            {
                if (log.IsInfoEnabled)
                {
                    var logEvent = new log4net.Core.LoggingEvent(
                                                    callerType,
                                                    log.Logger.Repository,
                                                    log.Logger.Name,
                                                    log4net.Core.Level.Info,
                                                    String.Empty,
                                                    null
                                                );

                    logEvent.Properties["Name"] = callName;
                    logEvent.Properties["Timestamp"] = DateTime.Now;
                    logEvent.Properties["Parameters"] = "{" + ((parameters.Count() == 0)
                                                                ? string.Empty
                                                                : parameters.Select(i => string.Format("{0}:\"{1}\"", i.Key, i.Value))
                                                                           .Aggregate((accum, next) => accum + ", " + next))
                                                            + "}";

                    log.Logger.Log(logEvent);
                }
            }

            public static void LogMessage(Type callerType, string msg)
            {

                    log = log4net.LogManager.GetLogger(callerType.Name);
                    log.Info(msg);
                
            }

        }
    
}
